home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
flxlstc.exe
/
FLEXLIST.HKR
< prev
Wrap
Text File
|
1990-10-04
|
6KB
|
187 lines
/*
flexlist.hkr
10-4-90
Homogeneous-heterogeneous
hybrid stack-queue-list-array generic class.
K&R C
Copyright 1990
John W. Small
All rights reserved
PSW / Power SoftWare
P.O. Box 10072
McLean, Virginia 22102 8072
(703) 759-3838
*/
/* LINTLIBRARY */
#ifndef FLEXLIST_KR_C
#define FLEXLIST_KR_C
typedef unsigned size_t;
#define UINT_MAX -1
typedef char void;
#define const
/* FlexNode declarations */
typedef struct FlexNode_ FlexNode, *FlexN;
#define FlexN0 ((FlexN)0)
#define FlexNodeLinkage FlexN next, prev
struct FlexNode_ {
/* friend: FlexList */
FlexNodeLinkage;
/* public: */
char data[1];
};
/* Virtual functions for variant FlexNodes */
typedef struct {
/* friend: FlexList */
FlexN (*FNnew)(/* const void *D */);
int (*FNwrite)(/* void *ND, const void *D */);
int (*FNread)(/* const void *ND, void *D */);
int (*FNdestruct)(/* void *ND, void *D */);
} FlexNodeVFT, *FlexNVFT;
#define FlexNVFT0 ((FlexNVFT)0)
#define FNnew0 ((FlexN (*)(/* const void *D */)) 0)
#define FNwrite0 ((int (*)(/* void *ND, const void *D */)) 0)
#define FNread0 ((int (*)(/* const void *ND, void *D */)) 0)
#define FNdestruct0 ((int (*)(/* void *ND, void *D */)) 0)
/* String variant FlexNode functions */
extern FlexNodeVFT FlexNodeStrVFT;
/* FlexList header declaration */
typedef struct {
/* private: */
FlexN front, current, rear;
unsigned curNum, nodes, maxNodes;
size_t sizeofNodeData, sizeofNode;
int sorted;
int (*compare)(/* const void *D1, const void *D2 */);
FlexNVFT vft;
int (*FLDdestruct)(/* void *LD */);
char data[1];
} FlexList, *FlexL;
#define FlexL0 ((FlexL)0)
#define FLcomparE(compare) ((int (*)(/* const void *D1, \
const void *D2 */)) compare)
#define FLcompare0 FLcomparE(0)
#define FLDdestruct0 ((int (*)(/* void *LD */)) 0)
/* FlexList constructors/destructor - static headers */
extern FlexL FLfixed(/* FlexL L, size_t sizeofNodeData */);
extern FlexL FLunpack(/* FlexL L, size_t sizeofCell,
unsigned cells, const void *array */);
extern FlexL FLvariant(/* FlexL L, FlexNVFT vft */);
#define FLstr(L) FLvariant(/* L,&FlexNodeStrVFT */)
extern int FLclear(/* FlexL L */);
/* FlexList constructors/destructor - dynamic headers */
extern FlexL FLfixedNew(/* size_t sizeofNodeData,
size_t sizeofLocalData,
int (*FLDdestruct)(void *LD) */);
extern FlexL FLunpackNew(/* size_t sizeofCell,
unsigned cells, const void *array,
size_t sizeofLocalData,
int (*FLDdestruct)(void *LD) */);
extern FlexL FLvariantNew(/* FlexNVFT vft,
size_t sizeofLocalData,
int (*FLDdestruct)(void *LD) */);
#define FLstrNew(sizeofLocalData, FLDdestruct) \
FLvariantNew(&FlexNodeStrVFT, \
sizeofLocalData,FLDdestruct)
extern int FLdelete(/* FlexL *Lptr */);
/* FlexList header functions */
#define FLfrontD(L) (void *)((L)? (L)->front? \
(L)->front->data : 0 : 0)
#define FLcurrentD(L) (void *)((L)? (L)->current? \
(L)->current->data : 0 : 0)
#define FLrearD(L) (void *)((L)? (L)->rear? \
(L)->rear->data : 0 : 0)
#define FLcurNum(L) ((L)? (L)->curNum : 0)
#define FLnodes(L) ((L)? (L)->nodes : 0)
#define FLmaxNodes(L) ((L)? (L)->maxNodes : 0)
extern int FLsetMaxNodes(/* FlexL L, unsigned maxNodes */);
#define FLnotFull(L) ((L)? ((L)->maxNodes - (L)->nodes) : 0)
#define FLsizeofNodeData(L) ((L)? (L)->sizeofNodeData : 0)
#define FLisSorted(L) ((L)? (L)->sorted : 0)
#define FLunSort(L) ((L)? ((L)->sorted = 0, 1) : 0)
#define FLcompare(L) ((L)? (L)->compare : FLcompare0)
extern int FLsetCompare(/* FlexL L, int (*compare)
(const void *D1, const void *D2) */);
#define FLisFixed(L) FLsizeofNodeData(L)
#define FLisVariant(L) ((L)? (L)->vft : FlexNVFT0)
#define FLData(L) (void *)((L)? ((L)->FLDdestruct? \
(L)->data : 0) : 0)
/* FlexList stack and queue functions */
extern void *FLpushN(/* FlexL L, FlexN N */);
extern void *FLpushD(/* FlexL L, const void *D */);
extern FlexN FLpopN(/* FlexL L */);
extern int FLpopD(/* FlexL L, void *D */);
extern void *FLtopD(/* FlexL L, void *D */);
extern void *FLinsQN(/* FlexL L, FlexN N */);
extern void *FLinsQD(/* FlexL L, const void *D */);
/* FlexList list functions */
extern void *FLmkcur(/* FlexL L, unsigned n */);
extern void *FLinsN(/* FlexL L, FlexN N */);
extern void *FLinsD(/* FlexL L, const void *D */);
extern void *FLinsSortN(/* FlexL L, FlexN N */);
extern void *FLinsSortD(/* FlexL L, const void *D */);
extern FlexN FLdelN(/* FlexL L */);
extern int FLdelD(/* FlexL L, void *D */);
extern void *FLnextD(/* FlexL L, void *D */);
extern void *FLprevD(/* FlexL L, void *D */);
/* FlexList search/sort functions */
/* See also FLinsSortN()/FLinsSortD() list functions */
extern void *FLfindFirstD(/* FlexL L, const void *D */);
extern void *FLfindNextD(/* FlexL L, const void *D */);
extern void *FLfindLastD(/* FlexL L, const void *D */);
extern void *FLfindPrevD(/* FlexL L, const void *D */);
extern int FLsort(/* FlexL L, int (*compare)
(const void *D1, const void *D2) */);
/* FlexList array functions */
/* See also compaction functions */
extern int FLstoreD(/* FlexL L, const void *D, unsigned n */);
extern int FLrecallD(/* FlexL L, void *D, unsigned n */);
/* FlexList compaction functions */
/* See also FLunpack()/FLunpackNew() constructors */
extern void *FLpack(/* FlexL L */);
extern void **FLpackPtrs(/* FlexL L */);
/* FlexList implementation constants */
/* Change as required by target machine */
#define FLmaxMaxNodes UINT_MAX
#define FLmallocAlignLoss 16
#define FLmaxSizeofLocalData \
((size_t)(-(long)sizeof(FlexList) \
-FLmallocAlignLoss))
#define FLmaxSizeofNodeData \
((size_t)(-(long)sizeof(FlexNode) \
-FLmallocAlignLoss))
#define FLmaxSizeofArray \
((long)(size_t)-FLmallocAlignLoss)
#endif